/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package server;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;


class Pair {
    public String argument;
    public String value;
    
    public Pair(String r1, String r2) {
        argument = r1;
        value = r2;
    }
}
/**
 *
 * @author Peewhy
 */
public class FileParser implements Iterable<Pair>{
    private String fname;
    public BufferedReader in;
    
    public FileParser(String filename) {
        fname = filename;
        init();
    }
    
    private void init(){
        try {
            in = new BufferedReader(new FileReader(fname));
        }
        catch (Exception e) {}
    }
    
    
    public Iterator<Pair> iterator() {
        init();
        return new Iterator<Pair>() {
            public String str;            
            
            public boolean hasNext() {
                try {
                    return (str = in.readLine()) != null;
                } catch (IOException ex) {
                    Logger.getLogger(FileParser.class.getName()).log(Level.SEVERE, null, ex);
                    return false;
                }
            }

            public Pair next() {
                String[] mas = str.split(":");                
                try {
                    return new Pair (mas [0].trim(), mas [1].trim());
                }
                catch (IndexOutOfBoundsException er) {
                    return new Pair(str, "");
                }
            }

            public void remove() {
                throw new UnsupportedOperationException("Not supported yet.");
            }
            
        };
    }

    
}
